﻿using System;
using System.Web.Mvc;
using EditorialProyectos.Website.Infrastructure;
using Whoever.Framework.Utils;
using Whoever.Framework.CustomException;
using Whoever.Patterns.MVC.Filters;
using Whoever.Patterns.MVC.Models;

using EditorialProyectos.Website.Models;
using EditorialProyectos.Business;
using EditorialProyectos.Business.Entities;

using Whoever.Framework.Enum;

namespace EditorialProyectos.Website.Controllers
{
    public class ViewProjectController : Controller
    {
        public ActionResult Main(int id)
        {
            var projectViewModel = new ViewProjectViewModel();
            
            projectViewModel.Entity = ManagerFactory.ProjectManager.GetById(new Project { Id = id });

            ManagerFactory.ProjectManager.FillSelectablesRelations(projectViewModel);

            projectViewModel.CategoryList = null;

            projectViewModel.InvestmentViewModel = new InvestmentViewModel();
            projectViewModel.InvestmentViewModel.Entity.ProjectId = id;

            projectViewModel.CommentViewModel = new CommentViewModel();
            projectViewModel.CommentViewModel.Entity.ProjectId = id;
            projectViewModel.CommentViewModel.List = ManagerFactory.CommentManager.GetByProjectId(id);

            projectViewModel.Entity.Html = "";

            return View(projectViewModel);
        }

        [AJAXExceptionHandler]
        public ActionResult GetHtml(int id)
        {
            return Json(ManagerFactory.ProjectManager.GetHtml(id));
        }

        public ActionResult GetPartial(string partialName)
        {
            var model = new ProjectViewModel();

            ManagerFactory.ProjectManager.FillSelectablesRelations(model);

            return PartialView(partialName, model);
        }
    }
}
